#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>


#define DATA_SIZE 32 


extern char __DATA_START; 

/* pointer to the result */
char *result = 0;

char *mb_ready; //=(char *) 0x120 + 10 ; //microblaze finish sending data
char *rv_ready; //=(char *) 0x128 ; //rovex ready to receive new data
char *hs[2];

char *mb_data[DATA_SIZE]; // fetch from 0x120 -> 0x1B5
char image [DATA_SIZE *2]; 

char sum; 
int i_sum; 

char *test; 
int int_value; 
int *int_ptr; 


int main(void)
{
	int i;
	int r;
	int proceed=0; 

//---------------------------------------------------
/* read first buffer */



	//0x120 - 0x13F
	for(i=0; i < DATA_SIZE ; i++)
	{
		mb_data[i]= (char * ) 0x120 + i * sizeof(char);		  
  
	}


	/*save first image*/
	for(i=0; i <DATA_SIZE  ; i++)
	{
	//	*mb_data[i]= *mb_data[i] +1 ; 
	      image[i]= *mb_data[i] ; 
	}


//---------------------------------------------------
/* handshaking*/
	
	/*notify microblaze that firt data is processed */
/*	rv_ready= (char *) 0x130;
	*rv_ready = 44;

	//wait until microblaze sends new data 
	mb_ready= (char *) 0x138;
	while(*(mb_ready) != 33  )	
		mb_ready= (char *) 0x138;
*/
//---------------------------------------------------

/*read second buffer */
//fetch 0x140 - 0x15F
 		
	for(i=0; i < DATA_SIZE ; i++)
	{
//   		mb_data[i]= (char *) 0x120 + i * sizeof(char);		  

   	mb_data[i]= (char *) 0x120 + DATA_SIZE + i * sizeof(char);		  
	}

	/*save second image*/
	for(i=0; i <DATA_SIZE  ; i++)
	{
	       image[i+DATA_SIZE]= *mb_data[i] ; 
	       // image[i+DATA_SIZE]= 34 ; 
	}



/*validate dmem data */
  //int_ptr=(int *) 0x13C ; //position in dmem for result
  int_ptr=(int *) 0x120 ; //position in dmem for result


/*sum values */
i_sum=0;
//for(i=0; i<DATA_SIZE; i++)
for(i=0; i<sizeof(image); i++)
{ 
    i_sum= i_sum + image[i]; 
} 

 *int_ptr=i_sum;












	return 0;
}
